/* 高级自定义密码验证 */
Ext.apply(Ext.form.VTypes, {
			/* val指当前文本框值，field指当前文本框组件 */
			password : function(val, field) {
				var rnt = false;
				/* 待比较目标文本框组件 */
				if (field.confirmTo) {
					var pwd = Ext.get(field.confirmTo);
					if (val == pwd.getValue()) {
						rnt = true;
					} else {
						rnt = false;
						// Ext.Msg.alert('提示', '密码确认错误！');
					}
				}
				return rnt;
			}
		});

document.write("<script src=\"" + context
		+ "/system/user/js/editpwd.js\"></script>");
/**
 * 待办事项统计
 */
function loadPendingStat(size) {
	var url = context + '/system/flowstat.do?method=pending4Json';
	Ext.Ajax.request({
		// 请求地址
		url : url,
		scriptTag : true,
		// 成功时回调
		success : function(response, options) {
			var json = response.responseText;
			var o = Ext.util.JSON.decode(json);

			var pendingListTxt = '';

			var idx = 0;

			var editURL = '/system/flowlist.do?method=mypendinglist&key=';

			Ext.each(o.list, function(item) {
				pendingListTxt += '<LI class="blues">';
				pendingListTxt += '<img src="' + context
						+ '/newframe/images/icon3.gif">';
				pendingListTxt += '&nbsp;&nbsp;<A href="javascript:void(0);" onClick="switchMenu(\''
						+ editURL
						+ item.CG_KEY
						+ '\');">'
						+ item.CG_NAME
						+ ' (' + item.CT + ')</A></LI>';
				idx++;
			});

			for (var i = idx; i < size; i++) {
				pendingListTxt += '<LI class="blues">&nbsp;</LI>';
				idx++;
			}

			$('pendingstatUL').innerHTML = pendingListTxt;
		},
		failure : function(response, options) {
			alert('获取信息出现异常!');
		}
	});
}

/**
 * 待办公文列表
 */
function loadPendingList(size) {
	var url = context + '/system/flowlist.do?method=pendinglist4Json&size='
			+ size;
	Ext.Ajax.request({
		// 请求地址
		url : url,
		scriptTag : true,
		// 成功时回调
		success : function(response, options) {
			var json = response.responseText;
			var o = Ext.util.JSON.decode(json);

			var pendingListTxt = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="bdr_nt table_01">';

			var idx = 0;

			var editURL = '/system/flow.do?method=edit&id=';

			Ext.each(o.list, function(item) {
				pendingListTxt += '<tr title="' + formatTime(item.A_STIME)
						+ ' 接收">';
				pendingListTxt += '<td width="2%" align="center"><img src="'
						+ context
						+ '/newframe/images/n_30.gif" width="3" height="3" /></td>';
				pendingListTxt += '<td width="42%" align="left" class="blues"><div class="divn"><a title="点击办理公文" href="javascript:void(0);" onclick="javascript:switchMenu(\''
						+ editURL
						+ item.A_ID
						+ '\');">'
						+ item.A_TITLE
						+ '</a></div></td>';
				pendingListTxt += '<td width="18%" align="center">'
						+ item.S_NAME + '</td>';
				pendingListTxt += '<td width="18%" align="center">'
						+ formatDate(item.A_STIME) + '</td>';
				pendingListTxt += '<td width="20%" align="center">'
						+ item.INS_OBJECT + '</td>';
				pendingListTxt += '</tr>';

				idx++;
			});

			for (var i = idx; i < size; i++) {
				pendingListTxt += '<tr>';
				pendingListTxt += '<td colspan="5"><div class="divn">&nbsp;</div></td>';
				pendingListTxt += '</tr>';
			}

			pendingListTxt += '</table>';

			$('paddingList').innerHTML = pendingListTxt;
		},
		failure : function(response, options) {
			alert('获取信息出现异常!');
		}
	});
}

/**
 * 文件传阅列表
 * 
 */
function loadCCList(size) {
	var url = context + '/system/flowlist.do?method=myencycliclist4json&size='
			+ size;
	Ext.Ajax.request({
		// 请求地址
		url : url,
		scriptTag : true,
		// 成功时回调
		success : function(response, options) {
			var json = response.responseText;
			var o = Ext.util.JSON.decode(json);

			var pendingListTxt = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="bdr_nt table_01">';

			var idx = 0;

			var editURL = context + '/system/flow.do?method=viewencyclic&id=';

			Ext.each(o.list, function(item) {
				pendingListTxt += '<tr>';
				pendingListTxt += '<td width="2%" align="center"><img src="'
						+ context
						+ '/newframe/images/n_30.gif" width="3" height="3" /></td>';
				pendingListTxt += '<td width="42%" align="left" class="blues"><div class="divn"><a title="点击查阅公文" href="'
						+ editURL
						+ item.A_ID
						+ '" target="_blank">'
						+ item.A_TITLE + '</a></div></td>';
				pendingListTxt += '<td width="18%" align="center">'
						+ item.S_NAME + '</td>';
				pendingListTxt += '<td width="18%" align="center">'
						+ formatDate(item.A_STIME) + '</td>';
				pendingListTxt += '<td width="20%" align="center">'
						+ item.INS_OBJECT + '</td>';
				pendingListTxt += '</tr>';

				idx++;
			});

			for (var i = idx; i < size; i++) {
				pendingListTxt += '<tr>';
				pendingListTxt += '<td colspan="5"><div class="divn">&nbsp;</div></td>';
				pendingListTxt += '</tr>';
			}

			pendingListTxt += '</table>';

			$('ccList').innerHTML = pendingListTxt;
		},
		failure : function(response, options) {
			alert('获取信息出现异常!');
		}
	});
}

/**
 * 发文传阅列表
 */
function loadEndList(size) {
	var url = context + '/system/flowlist.do?method=endlist4json&size=' + size;
	Ext.Ajax.request({
		// 请求地址
		url : url,
		scriptTag : true,
		// 成功时回调
		success : function(response, options) {
			var json = response.responseText;
			var o = Ext.util.JSON.decode(json);

			var pendingListTxt = '<table width="100%" border="0" cellspacing="0" cellpadding="0" class="bdr_nt table_01">';

			var idx = 0;

			var idx = 0;

			var editURL = context + '/system/flow.do?method=lookover&id=';

			Ext.each(o.list, function(item) {
				pendingListTxt += '<tr>';
				pendingListTxt += '<td width="2%" align="center"><img src="'
						+ context
						+ '/newframe/images/n_30.gif" width="3" height="3" /></td>';
				pendingListTxt += '<td width="42%" align="left" class="blues"><div class="divn"><a title="点击查阅公文" href="'
						+ editURL
						+ item.A_ID
						+ '" target="_blank">'
						+ item.A_TITLE + '</a></div></td>';
				pendingListTxt += '<td width="18%" align="center">'
						+ item.USERUNIT + '/' + item.USERNAME + '</td>';
				pendingListTxt += '<td width="18%" align="center">'
						+ formatDate(item.A_STIME) + '</td>';
				pendingListTxt += '<td width="20%" align="center">'
						+ item.INS_OBJECT + '</td>';
				pendingListTxt += '</tr>';

				idx++;
			});

			for (var i = idx; i < size; i++) {
				pendingListTxt += '<tr>';
				pendingListTxt += '<td colspan="5"><div class="divn">&nbsp;</div></td>';
				pendingListTxt += '</tr>';
			}

			pendingListTxt += '</table>';

			$('endList').innerHTML = pendingListTxt;
		},
		failure : function(response, options) {
			alert('获取信息出现异常!');
		}
	});
}

/**
 * 初始化栏目信息
 * 
 * @param {}
 *            key 栏目key
 * 
 * @param {}
 *            fun 回调函数
 */
function initInfoArea(key, size, area, img) {
	var url = context + '/app/Vinfo.do?method=infolistjason&key=' + key
			+ '&size=' + size;

	Ext.Ajax.request({
				// 请求地址
				url : url,
				scriptTag : true,
				// 成功时回调
				success : function(response, options) {
					var json = response.responseText;
					var o = Ext.util.JSON.decode(json);

					if (o.success) {
						var list = o.infoList;
						loadInfoList(key, size, area, o.name, img, list);
					} else {
						// return '[]';
					}
				}
			});
}

/**
 * 初始化内容信息列表
 * 
 * @param {}
 *            key 栏目唯一标识
 * @param {}
 *            size 栏目信息数量
 * @param {}
 *            area 栏目所在区域
 * @param {}
 *            name 栏目名称
 * @param {}
 *            list 栏目信息列表
 */
function loadInfoList(key, size, area, name, img, list) {
	var str = '<ul>';

	var url = context + '/app/Vinfo.do?method=viewinfo&id=';

	var idx = 0;

	Ext.each(list, function(item) {
		str += '<li><div class="divn" style="width:200px;"><span class="gray"><a title="'
				+ '['
				+ item.date
				+ ']'
				+ item.title
				+ '" target="_blank" href="' + url + item.id + '">';
		str += item.title;
		str += '</a></span></div></li>';

		idx++;
	});

	for (var i = idx; i < size; i++) {
		str += '<li>&nbsp;</li>';

		idx++;
	}

	str += '</ul>';

	$(area).innerHTML = str;
}

/**
 * 我的文件接收列表
 */
function loadMyFile(size) {
	var url = context + '/app/wjcs.do?method=jslist4json&size=' + size;
	Ext.Ajax.request({
		// 请求地址
		url : url,
		scriptTag : true,
		// 成功时回调
		success : function(response, options) {
			var json = response.responseText;
			var o = Ext.util.JSON.decode(json);

			var pendingListTxt = '';

			var idx = 0;

			Ext.each(o.list, function(item) {
				pendingListTxt += '<LI class="blues">';
				pendingListTxt += '<img src="' + context
						+ '/newframe/images/icon3.gif">';
				pendingListTxt += '&nbsp;&nbsp;<A href="javascript:void(0);" onClick="viewFile(\''
						+ item.XSYSTEM_ANNEX_ID
						+ '\', \''
						+ item.ID
						+ '\');">'
						+ item.ANNEX_NAME + '</A></LI>';
				idx++;
			});

			for (var i = idx; i < size; i++) {
				pendingListTxt += '<LI class="blues">&nbsp;</LI>';
				idx++;
			}

			$('myfilesUL').innerHTML = pendingListTxt;
		},
		failure : function(response, options) {
			alert('获取信息出现异常!');
		}
	});
}

ddlevelsmenu.addEvent(window, function() {
			initDesktop();
		}, 'load');

function initDesktop() {
	inithelper();
	
	$('middleTD').width = document.body.clientWidth - $('leftTD').width
			- $('rightTD').width;

	var size = 8;

	loadPendingStat(7);

	loadMyFile(10);

	loadPendingList(7);

	loadCCList(7);

	loadEndList(7);

	initInfoArea('root_tzgg', size, 'tzggArea', context
					+ '/newframe/images/tzgg.png');

	// initInfoArea('root_hyjy', loadZWXXInfoList);

	initInfoArea('root_hyjy', size, 'hyjyArea', context
					+ '/newframe/images/hyjy.png');

	initInfoArea('root_gzzd', size, 'gzzdArea', context
					+ '/newframe/images/gzzd.png');
}

function viewFile(aid, id) {
	var url = context + '/app/wjcs.do?method=read&id=' + id;
	Ext.Ajax.request({
				// 请求地址
				url : url,
				scriptTag : true,
				// 成功时回调
				success : function(response, options) {
					var json = response.responseText;
					var o = Ext.util.JSON.decode(json);

					viewAnnex(aid);
				},
				failure : function(response, options) {
					alert('查阅文件出现异常!');
				}
			});
}
